/*
 * 创建项目目录结构【脚手架建造】
 * @author li.xiaoxi
 * @date 2016-12-21
 */
var fs = require('fs')
require('shelljs/global')

//全局配置
var init_config = global.think_config.init

//创建babelrc文件
var createBabelrc = function(){
  var name = '.babelrc',
      jsonStr = JSON.stringify({
        "presets": ["es2015", "stage-2"],
        "plugins": ["transform-runtime"],
        "comments": false
      });

  fs.writeFile(name, jsonStr, function(err) {
    if(err) return;
  })
  console.log('成功：【创建文件】.babelrc')
}

module.exports = function(){
  var html = init_config.html,
      app = init_config.app,
      src = init_config.src,
      css = init_config.styles,
      js = init_config.scripts;


  var createDir = function(dir){
      mkdir('-p', dir)
      console.log('【创建目录】' + dir)
  }

  //需要生成的目录数组
  var dirArr = [
                app,
                app+'/'+src,
                app+'/'+src+'/'+css,
                app+'/'+src+'/'+js,
                app+'/'+html
      ];

  dirArr.forEach(function(item){
      createDir(item)
  });

  //createBabelrc();
  console.log('成功：创建项目脚手架')
}
